package com.colorlight.cloud.complete.entity.instructions;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.complete.api.CompleteEntityScheduleActions;
import com.colorlight.cloud.complete.entity.po.FunctionIndex;
import com.colorlight.iot.proto.complete.instruction.CompleteInstruction;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 多功能卡恢复出厂
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class FunctionFactoryRestore implements CompleteEntityScheduleActions {

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class InputMsg implements Serializable {
        /**
         * 功能序号
         */
        private List<FunctionIndex> function;
    }

    @Data
    @NoArgsConstructor
    @Builder
    public static class OutputMsg implements Serializable {
    }

    private InputMsg inputMsg;
    private OutputMsg outputMsg;

    @Override
    public ByteString objectConvertBytes() {
        final CompleteInstruction.FunctionFactoryRestore.InputMsg.Builder inputMsgBuilder =
                CompleteInstruction.FunctionFactoryRestore.InputMsg.newBuilder();
        FunctionFactoryRestore.InputMsg thisInput = this.getInputMsg();
        inputMsgBuilder.addAllFunction(thisInput.getFunction().stream().map(FunctionIndex::toProto).collect(Collectors.toList()));

        final CompleteInstruction.FunctionFactoryRestore.Builder builder =
                CompleteInstruction.FunctionFactoryRestore.newBuilder();
        builder.setInput(inputMsgBuilder);
        return builder.build().toByteString();
    }

    @Override
    public FunctionFactoryRestore byteConvertObject(ByteString bytes) {
        this.setOutputMsg(new FunctionFactoryRestore.OutputMsg());
        return this;
    }
}

